<?php
namespace app\model;

use think\Model;
use think\Db;

class MeetingModel extends Model
{
    protected $table = 'meeting';
    protected $resultSetType = 'collection';


    public function getVistList( $page , $pagesize ,$companyid, $fields = '*'){
        $sql = 'SELECT '.$fields.' FROM `user` WHERE id IN (
            SELECT t.uid FROM ((SELECT DISTINCT uid FROM `meeting` WHERE ( 1=1 ) AND `appointment_companyid`='.$companyid.' ) as t)
        ) LIMIT '.$page.','.$pagesize;
        $result = DB::query($sql);

        if($result){
            $blacklist = DB::table('blacklist')->where('companyid',$companyid)->value('blacklist');            
            foreach($result as &$item){
                //状态
                if($blacklist){
                    $userArr = explode(',',$blacklist);
                    $item['status'] = in_array($item['id'],$userArr) ? 1 : 0;
                }else{
                    $item['status'] = 0;
                }    
                //访问次数
                $count = DB::table('meeting')->where('uid',$item['id'])->where('appointment_companyid',$companyid)->where('status',3)->count();
                $item['count'] = $count;
            }
        }
        return $result;
    }

    


}
